package nju.bean.meeting.clientManagement;

import java.io.IOException;
import java.util.ArrayList;

import nju.bean.meeting.UML.Executable;
import nju.bean.meeting.data.RecordSummary;
import nju.bean.meeting.net.ClientSimpleBearer;
import nju.bean.meeting.transporter.Feedback.RecordFeedback;
import nju.bean.meeting.transporter.Feedback.RecordSummaryFeedback;
import nju.bean.meeting.transporter.Request.RecordRequest;
import nju.bean.meeting.transporter.Request.RecordSummaryRequest;

public class RecordClient {

	static private RecordClient instance;
	private ClientSimpleBearer inforSender;
	
	private RecordClient(){
		
	}
	
	static public RecordClient getInstance(){
		if(instance == null)
			instance = new RecordClient();
		return instance;
	}
	
	public void setBearer(ClientSimpleBearer inforSender){
		this.inforSender = inforSender;
	}
	
	public ArrayList<RecordSummary> requestRecordSummary(String userName) throws IOException{
		Object ob = inforSender.sendRequest(new RecordSummaryRequest(userName));
		RecordSummaryFeedback rsf = (RecordSummaryFeedback)ob;
		if(rsf.getList()==null)
			return new ArrayList<RecordSummary>();
		ArrayList<RecordSummary> summaryList = (ArrayList<RecordSummary>)rsf.getList();
		return summaryList;
	}
	
	public ArrayList<Executable> requestRecord(String mId) throws IOException{
		Object ob = inforSender.sendRequest(new RecordRequest(mId));
		RecordFeedback rsb = (RecordFeedback)ob;
		ArrayList<Executable> record = (ArrayList<Executable>)rsb.getRecord();
		if(record == null)
			System.out.print("null");
		return record;
	}
}
